//package com.zengqingfa.springboot.validation.demo.handler;
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.NotReadablePropertyException;
//import org.springframework.http.HttpStatus;
//import org.springframework.validation.BindingResult;
//import org.springframework.validation.FieldError;
//import org.springframework.web.bind.MethodArgumentNotValidException;
//import org.springframework.web.bind.annotation.ExceptionHandler;
//import org.springframework.web.bind.annotation.ResponseStatus;
//import org.springframework.web.bind.annotation.RestControllerAdvice;
//
//import javax.validation.ConstraintViolationException;
//
///**
// * @fileName: ControllerExceptionHandler
// * @author: zengqf3
// * @date: 2020-10-6 18:04
// * @description:
// */
//@RestControllerAdvice
//@Slf4j
//public class ControllerExceptionHandler {
//
//    @ExceptionHandler({MethodArgumentNotValidException.class})
//    @ResponseStatus(HttpStatus.OK)
//    public String handleMethodArgumentNotValidException(MethodArgumentNotValidException ex) {
//        BindingResult bindingResult = ex.getBindingResult();
//        StringBuilder sb = new StringBuilder("校验失败:");
//        for (FieldError fieldError : bindingResult.getFieldErrors()) {
//            sb.append(fieldError.getField()).append("：").append(fieldError.getDefaultMessage()).append(", ");
//        }
//        log.info("ex:{}", sb.toString());
//        return sb.toString();
//    }
//
//    @ExceptionHandler({ConstraintViolationException.class})
//    @ResponseStatus(HttpStatus.OK)
//    public String handleConstraintViolationException(ConstraintViolationException ex) {
//        log.info("ex:{}", ex.getMessage());
//        return ex.getMessage();
//    }
//
//    @ExceptionHandler({NotReadablePropertyException.class})
//    @ResponseStatus(HttpStatus.OK)
//    public String handleNotReadablePropertyException(NotReadablePropertyException ex) {
//        log.info("ex:{}", ex.getMessage());
//        return ex.getMessage();
//    }
//
//}
